<template>
	<view :style="themeColor">
		<view class="page">
			<!-- <view class="flex flex-wrap align-center justify-center benben-position-layout flex passwordLogin_flex_0" :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class=""></view>
				<view class="title_text">登录注册</view>
				<view class=""></view>
			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view> -->
			<view class="title_bg"></view>

			<view class="store_info">
				<view class="store_1">中出行租车</view>
				<view class="store_2">中出行租车·真的好租</view>
				<image :src='STATIC_URL+"284.png"'></image>
			</view>
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout passwordLogin_flex_2">
				<!-- <text class='passwordLogin_fd2_0'>申请获取以下权限</text>
				<text class='passwordLogin_fd2_1'>获取你的公开信息（昵称、头像、地区等）</text> -->
				<!-- <view class='flex flex-wrap align-center justify-center passwordLogin_fd2_2' @tap.stop="LoginFunc()">
					<text class='passwordLogin_fd2_2_c1'>手机号快捷登录</text>
				</view> -->

				<!-- #ifdef MP-TOUTIAO -->
				<button @tap.stop="getPhoneTip" class='flex flex-wrap align-center justify-center passwordLogin_fd2_2'
					v-if="!is_tick">
					<text class='passwordLogin_fd2_2_c1'>抖音手机号授权快捷登录</text>
				</button>
				<button v-else class='flex flex-wrap align-center justify-center passwordLogin_fd2_2'
					open-type="getPhoneNumber" @getphonenumber="getPhoneNumberHandler">
					<text class='passwordLogin_fd2_2_c1'>抖音手机号授权快捷登录</text>
				</button>
				<!-- #endif -->
				
				
				<!-- #ifdef MP-WEIXIN || H5 -->
				<button @tap.stop="getPhoneTip" class='flex flex-wrap align-center justify-center passwordLogin_fd2_2'
					v-if="!is_tick">
					<text class='passwordLogin_fd2_2_c1'>手机号快捷登录</text>
				</button>
				<button v-else class='flex flex-wrap align-center justify-center passwordLogin_fd2_2'
					open-type="getPhoneNumber" @getphonenumber="getPhoneNumberWeixin">
					<text class='passwordLogin_fd2_2_c1'>手机号快捷登录</text>
				</button>
				<!-- #endif -->
				
				<!-- #ifdef MP-ALIPAY || H5 -->
				<button @tap.stop="getPhoneTip" class='flex flex-wrap align-center justify-center passwordLogin_fd2_2'
					v-if="!is_tick">
					<text class='passwordLogin_fd2_2_c1'>手机号快捷登录</text>
				</button>
				<button v-else class='flex flex-wrap align-center justify-center passwordLogin_fd2_2'
					open-type="getPhoneNumber" @getphonenumber="getPhoneNumberAlipay">
					<text class='passwordLogin_fd2_2_c1'>手机号快捷登录</text>
				</button>
				<!-- #endif -->


				<!-- <view class="code_login" @tap.stop="goCodeLogin">验证码登录</view> -->
			</view>

			<view class="flex flex-wrap align-center justify-center flex passwordLogin_flex_3" @tap.stop="is_tick = !is_tick">
				<template v-if="is_tick">
					<view class='flex flex position-relative align-center'>
						<image class='passwordLogin_checkfd3_0_c0_c0' :src='STATIC_URL+"7.png"'>
						</image>
					</view>
				</template>
				<template v-else>
					<view class='flex flex position-relative justify-end align-center'>
						<image class='passwordLogin_noCheckfd3_0_c1_c0'  :src='STATIC_URL+"8.png"'>
						</image>
					</view>
				</template>
				
				<text class='passwordLogin_fd3_1'>我已阅读并同意</text>
				<text class='passwordLogin_fd3_2' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/denglu/agreement/agreement?aid=7`">用户注册协议</text>
				<text class='passwordLogin_fd3_1'>{{$t('与')}}</text>
				<text class='passwordLogin_fd3_2' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/denglu/agreement/agreement?aid=6`">隐私政策</text>

			</view>

		</view>
	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},


		data() {
			return {
				"popupShow1658998215973": false,
				"is_tick": false,
				"code": "",
				"openid": "",
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {

		},
		onLoad(options) {
			
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			this.initCode();
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			initCode() {
				let _this = this;
				uni.login({
					success: res => {
						console.log(res);
						_this.code = res.code;
					},
					fail: err => {
						console.log(err);
					}
				})
			},
			getPhoneTip() {
				if (!this.is_tick) {
					this.$message.info('请阅读并同意用户注册协议与隐私政策');
					return false;
				}
			},
			// 抖音获取手机号登录
			getPhoneNumberHandler(e) {
				console.log(e);
				if (e.detail.errMsg.indexOf("user deny") !== -1) {
					uni.navigateBack();
				} else {
					// this.LoginFunc(e.detail.encryptedData, e.detail.iv);
					let _this = this;
					if (!_this.code) {
						_this.$message.info('获取code失败，请重试');
						_this.initCode();
					}
					uni.showLoading({
						title: '登录中...'
					})
					
					_this.$api.post(global.apiUrls.postgetOpenid, {
						code: _this.code,
						type: 1
					}).then(res => {
						if (res.data.code == 1) {
							_this.$api.post(global.apiUrls.postlogin, {
								encrypted_data: e.detail.encryptedData,
								iv: e.detail.iv,
								session_key: res.data.data.session_key,
								openid: res.data.data.openid,
								login_type: 1,
								city_code: uni.getStorageSync('city') ? uni.getStorageSync('city').citycode : "",
								extension_info: global.startData ? global.startData : ""
							}).then(result => {
								console.log("后台返回登录信息", result)
								if (result.data.code == 1) {
									uni.hideLoading();
									if (result.data.data) {
										_this.$message.info(result.data.info);
										//存入本地
										_this.$store.commit('updateUserInfo', result
											.data.data);
										_this.$store.commit('saveToken', result.data
											.data.token);
										setTimeout(() => {
											getApp().getOrderReminder();
											// uni.switchTab({
											// 	url: '/pages/tabBar/index/index'
											// })
											uni.navigateBack();
										}, 800)
									}
								} else {
									uni.hideLoading();
									_this.$message.info(result.data.info);
								}
							}).catch(err => {
								console.log('ERROR', err);
								uni.hideLoading();
								_this.$message.info(err.data.info);
							})
						} else {
							uni.hideLoading();
							_this.$message.info(res.data.info);
						}
					})
				}
			},
			// 微信获取手机号登录
			getPhoneNumberWeixin(e) {
				console.log(e);
				if (e.detail.errMsg.indexOf("user deny") !== -1) {
					uni.navigateBack();
				} else {
					// this.LoginFunc(e.detail.encryptedData, e.detail.iv);
					let _this = this;
					if (!_this.code) {
						_this.$message.info('获取code失败，请重试');
						_this.initCode();
					}
					uni.showLoading({
						title: '登录中...'
					})
					_this.$api.post(global.apiUrls.postgetOpenid, {
						code: _this.code,
						type: 2
					}).then(res => {
						// console.log(res);
						if (res.data.code == 1) {
							_this.openid = res.data.data.openid;
							_this.$api.post(global.apiUrls.postlogin, {
								openid: _this.openid,
								code: e.detail.code,
								login_type: 2,
								city_code: uni.getStorageSync('city') ? uni.getStorageSync('city').citycode : ""
							}).then(result => {
								// console.log("后台返回登录信息", result)
								if (result.data.code == 1) {
									uni.hideLoading();
									if (result.data.data) {
										_this.$message.info(result.data.info);
										//存入本地
										_this.$store.commit('updateUserInfo', result
											.data.data);
										_this.$store.commit('saveToken', result.data
											.data.token);
										setTimeout(() => {
											getApp().getOrderReminder();
											// uni.switchTab({
											// 	url: '/pages/tabBar/index/index'
											// })
											uni.navigateBack();
										}, 800)
									}
								} else {
									uni.hideLoading();
									_this.$message.info(result.data.info);
								}
							}).catch(err => {
								console.log('ERROR', err);
								uni.hideLoading();
								_this.$message.info(err.data.info);
							})
							
						} else {
							uni.hideLoading();
							_this.$message.info(res.data.info);
						}
					})
				}
			},
			
			// 支付宝获取手机号登录
			getPhoneNumberAlipay(e) {
				console.log(e);
				if (e.detail.errMsg.indexOf("user deny") !== -1) {
					uni.navigateBack();
				} else {
					// this.LoginFunc(e.detail.encryptedData, e.detail.iv);
					let _this = this;
					if (!_this.code) {
						_this.$message.info('获取code失败，请重试');
						_this.initCode();
					}
					uni.showLoading({
						title: '登录中...'
					})
					_this.$api.post(global.apiUrls.postgetOpenid, {
						code: _this.code,
						// response: e.detail.encryptedData,
						type: 3
					}).then(res => {
						if (res.data.code == 1) {
							_this.openid = res.data.data.openid;
							_this.$api.post(global.apiUrls.postlogin, {
								openid: _this.openid,
								code: e.detail.encryptedData,
								login_type: 3,
								city_code: uni.getStorageSync('city') ? uni.getStorageSync('city').citycode : ""
							}).then(result => {
								console.log("后台返回登录信息", result)
								if (result.data.code == 1) {
									uni.hideLoading();
									if (result.data.data) {
										_this.$message.info(result.data.info);
										//存入本地
										_this.$store.commit('updateUserInfo', result
											.data.data);
										_this.$store.commit('saveToken', result.data
											.data.token);
										setTimeout(() => {
											getApp().getOrderReminder();
											// uni.switchTab({
											// 	url: '/pages/tabBar/index/index'
											// })
											uni.navigateBack();
										}, 800)
									}
								} else {
									uni.hideLoading();
									_this.$message.info(result.data.info);
								}
							}).catch(err => {
								console.log('ERROR', err);
								uni.hideLoading();
								_this.$message.info(err.data.info);
							})
							
						} else {
							uni.hideLoading();
							_this.$message.info(res.data.info);
						}
					})
				}
			},

			//登录
			LoginFunc() {
				if (this.is_tick === false) {
					this.$message.info('请阅读并同意用户注册协议与隐私政策');
					return false;
				}
				uni.showLoading({
					title: '登录中...'
				})
				var _this = this;
				let code = '';
				uni.login({
					success: res => {
						console.log(res);
						code = res.code;
						_this.$api.post(global.apiUrls.postgetOpenid, {
							code: res.code
						}).then(res => {
							if (res.data.code == 1) {
								_this.session_key = res.data.data.session_key;
								_this.openid = res.data.data.openid;
							} else {
								uni.hideLoading();
								_this.$message.info(res.data.info);
							}
						})
					},
					fail: err => {
						console.log(err);
					}
				})
				uni.getUserProfile({
					desc: '用于完善会员资料',
					success: infoRes => {
						// console.log(code)
						console.log(infoRes);

						_this.$api.post(global.apiUrls.postlogin, {
							encrypted_data: infoRes.encryptedData,
							iv: infoRes.iv,
							session_key: _this.session_key,
							openid: _this.openid,
							type: 1
						}).then(result => {
							console.log("后台返回登录信息", result)
							result = result.data;
							// return;
							if (result.code == 1) {
								uni.hideLoading();
								if (result.data.userinfo) {
									_this.$message.info(result.msg);
									//存入本地
									_this.$store.commit('updateUserInfo', result.data.userinfo);
									_this.$store.commit('saveToken', result.data.userinfo.user_token);
									setTimeout(() => {
										uni.switchTab({
											url: '/pages/tabBar/index/index'
										})
									}, 800)
								}
							} else if (result.code == -999) {
								uni.hideLoading();
								_this.$message.info('请绑定手机号');
								setTimeout(function() {
									uni.navigateTo({
										url: '/pages/denglu/getPhone/getPhone'
									})
								}, 800);
								// if (result.data.result) {
								// 	uni.setStorageSync('Wxinfo_tmp', result.data.result);
								// }
							} else {
								uni.hideLoading();
								_this.$message.info(result.msg);
							}
						}).catch(err => {
							console.log('ERROR', err);
							uni.hideLoading();
							_this.$message.info(err.msg);
						})
					},
					fail: err => {
						console.log(err);
					}

				})
			},

			goCodeLogin() {
				if (!this.is_tick) {
					this.$message.info('请阅读并同意用户注册协议与隐私政策');
					return false;
				}
				uni.navigateTo({
					url: '/pages/denglu/codeLogin/codeLogin'
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	.code_login {
		display: flex;
		align-items: center;
		justify-content: flex-end;
		margin-top: 32rpx;
		color: #FC5B03;
	}

	.title_bg {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 508rpx;
		// background: linear-gradient( 180deg, #FC5B03 0%, #FFFFFF 100%);
		background: linear-gradient(to bottom, #FFE5D7, #FFFFFF);
	}

	.store_info {
		position: relative;
		z-index: 10;
		text-align: center;
		margin-top: 36rpx;

		.store_1 {
			font-weight: bold;
			font-size: 48rpx;
			color: #111111;
			margin-bottom: 24rpx;
		}

		.store_2 {
			margin-top: 8rpx;
			font-weight: 400;
			font-size: 34rpx;
			color: #666666;
		}

		image {
			width: 640rpx;
			height: 640rpx;
		}
	}

	.title_text {
		font-weight: bold;
		font-size: 32rpx;
		color: #111111;
	}

	.set_fd3_0 {
		line-height: 50rpx;
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
		margin: 40rpx 0rpx 32rpx 0rpx;
		text-align: center;
	}

	.set_fd3_1 {
		line-height: 45rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		margin: 0rpx 0rpx 37rpx 0rpx;
		text-align: center;
		padding: 0 30rpx;
	}

	.set_fd3_2_c0 {
		border-top: 1px solid #eee;
		border-right: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		border-radius: 0rpx 0rpx 0rpx 16rpx;
		font-size: 32rpx;
		color: rgba(153, 153, 153, 1);
		width: 269rpx;
		height: 94rpx;
		line-height: 94rpx;
		font-weight: 500;
	}

	.set_fd3_2_c1 {
		border-top: 1px solid #eee;
		border-left: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		border-radius: 0rpx 0rpx 16rpx 0rpx;
		font-size: 32rpx;
		color: #1593FF;
		width: 269rpx;
		height: 94rpx;
		line-height: 94rpx;
		font-weight: 500;
	}

	.set_flex_3 {
		background: #fff;
		background-size: 100% !important;
		width: 540rpx;
		background-size: 100% auto !important;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.set_fd2_0 {
		border: 1px solid #BFBFBF;
		background: rgba(255, 255, 255, 0.3900);
		background-size: 100% !important;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: #333;
		width: 686rpx;
		height: 88rpx;
		line-height: 88rpx;
		font-weight: 500;
	}

	.set_flex_2 {
		width: 750rpx;
		height: 144rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
	}

	.tourist {
		font-size: 28rpx;
		color: #2BA5FF;
		margin-top: 32rpx;
		text-align: center;
	}

	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #fff;
	}

	.passwordLogin_flex_0 {
		width: 750rpx;
		height: 88rpx;
		position: relative;
		z-index: 10;
	}

	.passwordLogin_flex_1 {
		padding: 90rpx 0rpx 147rpx 0rpx;
	}

	.passwordLogin_fd1_1 {
		color: #333333;
		font-size: 36rpx;
		font-weight: 500;
	}

	.passwordLogin_fd1_0 {
		width: 180rpx;
		height: 180rpx;
		margin: 0rpx 0rpx 40rpx 0rpx;
		border-radius: 16rpx;
	}

	.passwordLogin_flex_2 {
		padding: 0rpx 55rpx 0rpx 55rpx;
		position: relative;
		z-index: 10;
	}

	.passwordLogin_fd2_2_c1 {
		font-weight: bold;
		font-size: 30rpx;
		color: #FFFFFF;
	}

	.passwordLogin_fd2_2 {
		width: 640rpx;
		height: 98rpx;
		background: linear-gradient(90deg, #FD9602 0%, #FC5B03 100%);
		border-radius: 16rpx;
	}

	.passwordLogin_fd2_1 {
		color: #808080;
		font-size: 24rpx;
		font-weight: 400;
		line-height: 33rpx;
		margin: 0rpx 0rpx 40rpx 0rpx;
	}

	.passwordLogin_fd2_0 {
		color: #1A1A1A;
		font-size: 32rpx;
		font-weight: 700;
		margin: 0rpx 0rpx 16rpx 0rpx;
	}

	.passwordLogin_flex_3 {
		background: #fff;
		width: 750rpx;
		padding: 48rpx 0;
	}

	.passwordLogin_fd3_2 {
		font-weight: 500;
		font-size: 24rpx;
		color: #FC5B03;
		text-decoration: underline;
		margin: 0 5rpx;
	}

	.passwordLogin_fd3_1 {
		font-size: 24rpx;
		font-weight: 400;
		color: rgba(153, 153, 153, 1);
	}

	.passwordLogin_noCheckfd3_0_c1_c0 {
		width: 32rpx;
		height: 32rpx;
		margin: 0rpx 16rpx 0rpx 0rpx;
		transform: translateY(-3rpx);
	}

	.passwordLogin_checkfd3_0_c0_c0 {
		width: 32rpx;
		height: 32rpx;
		margin: 0rpx 16rpx 0rpx 0rpx;
		transform: translateY(-3rpx);
	}

	::v-deep .passwordLogin_fd3_0 {
		// margin: 0rpx 16rpx 0rpx 0rpx;
		// transform: translateY(-3rpx);
	}
</style>